package tests.library.classloader;

import library.classloader.*;
import java.io.*;
import java.util.List;
import java.util.ListIterator;

public class ClassLoaderTest
{
  protected String classPath;
  protected JarClassLoader classLoader;
	
  public ClassLoaderTest(String path){
   classPath = path;
  }
  
  public void start(){
   String className = null;
   TestClass testClass = null;
   try{
   classLoader = new JarClassLoader(classPath);
   
   List listContent = classLoader.getContent();
   ListIterator it = listContent.listIterator();
   
   while(it.hasNext()) {
     String name = (String)it.next();
     System.out.println("name: " + name);
   }
   
   
   className = new String("tests.library.classloader.TestClass");
   
   Class c = classLoader.loadClass(className);
   testClass = (TestClass)c.newInstance();

   }catch(ClassNotFoundException e) {e.printStackTrace();}
   catch (InstantiationException e){
      System.err.println("Error create new instance " + className +
              " (" + e.getClass().getName() + ":" + e.getMessage() + ")");
   } catch (IllegalAccessException e) {
	      System.err.println("Illegal access " + className +
	                         " (" + e.getClass().getName() + ":" + e.getMessage() + ")");
   } catch (IOException e) {
      System.err.println("Illegal access " + className +
                         " (" + e.getClass().getName() + ":" + e.getMessage() + ")");
   }
  
   testClass.print();	  
  }
  
  public static void main(String[] args) {
   String base_path = "path to jar folder";
   String path = base_path + "test.jar";
   ClassLoaderTest test = new ClassLoaderTest(path);
   test.start();
  } 

}
